package com.item.yxlottery.yxlottery.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.item.yxlottery.yxlottery.R;
import com.item.yxlottery.yxlottery.base.BaseActivity;
import com.item.yxlottery.yxlottery.utils.Utils;
import com.orhanobut.hawk.Hawk;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by leo on 2017/1/11.
 * 个人信息修改
 */

public class UserAccountActivity extends BaseActivity implements View.OnClickListener {
    @Bind(R.id.useraccount_ll_logo)
    AutoLinearLayout mLlLogo;
    @Bind(R.id.useraccount_tv_username)
    TextView mTvUsername;
    @Bind(R.id.useraccount_ll_username)
    AutoLinearLayout mLlUsername;
    @Bind(R.id.useraccount_tv_phone)
    TextView mTvPhone;
    @Bind(R.id.useraccount_ll_phone)
    AutoLinearLayout mLlPhone;
    @Bind(R.id.useraccount_tv_realname)
    TextView mTvRealname;
    @Bind(R.id.useraccount_ll_realname)
    AutoLinearLayout mLlRealname;
    @Bind(R.id.useraccount_tv_IDcard)
    TextView mTvIDcard;
    @Bind(R.id.useraccount_ll_IDcard)
    AutoLinearLayout mLlIDcard;
    @Bind(R.id.useraccount_ll_pwd)
    AutoLinearLayout mLlPwd;
    @Bind(R.id.useraccount_tv_bankcard)
    TextView mTvBankcard;
    @Bind(R.id.useraccount_ll_bankcard)
    AutoLinearLayout mLlBankcard;
    @Bind(R.id.useraccount_iv_logo)
    ImageView mIvLogo;

    @Override
    protected void setCustomActionBar(ImageButton ibActionbarLeft, TextView tvActionBarTitle, ImageButton ibActionbarRight, AutoRelativeLayout layoutActionbar) {
        ibActionbarLeft.setImageResource(R.drawable.leftarrow);
        ibActionbarLeft.setOnClickListener(this);
        ibActionbarRight.setVisibility(View.GONE);
        tvActionBarTitle.setText("帐号管理");
    }

    @Override
    protected View initView() {
        View view = View.inflate(this, R.layout.activity_useraccount, null);
        ButterKnife.bind(this, view);

        return view;
    }

    @Override
    protected void initData() {
        setLogo();

        Intent intent = getIntent();
        mTvPhone.setText(intent.getStringExtra("mMemberName"));
        mTvRealname.setText(intent.getStringExtra("mMemberTruename"));
    }

    @Override
    protected void initEvent() {

    }

    @OnClick({R.id.useraccount_ll_logo, R.id.useraccount_ll_username, R.id.useraccount_ll_phone, R.id.useraccount_ll_realname, R.id.useraccount_ll_IDcard, R.id.useraccount_ll_pwd, R.id.useraccount_ll_bankcard})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ib_actionbar_left:
                finish();
                break;
            case R.id.useraccount_ll_logo://头像
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_username://昵称
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_phone://手机号码
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_realname://真实姓名
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_IDcard://身份证号
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_pwd://密码管理
                Utils.toast(this, "nihao");
                break;
            case R.id.useraccount_ll_bankcard://提现银行卡
                gotoActivity(MyBankCaredActivity.class);
                break;
        }
    }

    //显示logo头像
    private void setLogo() {

        Object url = R.drawable.minebg;

        String memberAvatar = Hawk.get("memberAvatar", "");// 用户头像地址

        if (!memberAvatar.equals("")) {
            //url = UrlUtil.getHomeUrl()+memberAvatar;
            url = "http://test.yiqiquan.net/upload/img/adv/1476355138828.jpg";
        }

        Glide.with(this).load(url)
                .asBitmap().centerCrop().into(new BitmapImageViewTarget(mIvLogo) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                mIvLogo.setImageDrawable(circularBitmapDrawable);
            }
        });
    }


}
